package com.cssw.fyzb.core.eao.video;

import com.alibaba.fastjson.JSON;
import com.cssw.fyzb.core.es.EsClient;
import com.cssw.fyzb.core.model.eos.AtMeEo;
import com.cssw.fyzb.core.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author Jian Qin.
 */
@Component
public class AtMeEaoImpl implements AtMeEao{
    @Autowired
    private EsClient esClient;

    private final static String INDEX_NAME = "fyzb_atme";
    private final static String TYPE_NAME = "atme";

    @Override
    public void save(Long userId, Long toUserId, Long commentId, Long videoId,
                     String comment, String thumb, String content, Date date) {
        AtMeEo atMeEo = new AtMeEo();
        atMeEo.setUserId(userId);
        atMeEo.setTo_userId(toUserId);
        atMeEo.setCommentId(commentId);
        atMeEo.setComment(comment);
        atMeEo.setContent(content);
        atMeEo.setThumb(thumb);
        atMeEo.setCreateTime(DateUtil.format(date));
        atMeEo.setVideoId(videoId);
        atMeEo.setIsVideo(videoId != null ? "1" : "0");


        esClient.getClient()
                .prepareIndex(INDEX_NAME, TYPE_NAME)
                .setSource(JSON.parseObject(JSON.toJSONString(atMeEo)))
                .get()
        ;

    }
}
